﻿@Html.DevExpress().GridView(
    settings => {
        settings.Name = "gvEditing";
        settings.KeyFieldName = "FIPGroupID";
        settings.CallbackRouteValues = new { Controller = "IPGroupManager", Action = "IPGroupManagerListPartial" };
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(96);
        
        settings.Columns.Add(column =>
        {
            column.Caption = "操作";

            column.SetDataItemTemplateContent(c =>
            {
                Html.DevExpress().HyperLink(s => { 
                    s.Name = "linkEdit" + c.VisibleIndex; 
                    s.Properties.Text = "修改"; 
                    s.ToolTip = "修改"; 
                    s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_Edit.png");
                    s.Properties.ClientSideEvents.Click = "function(){Edit('" + DataBinder.Eval(c.DataItem, "FIPGroupID") + "')}"; 
                    s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer"); 
                }).GetHtml();
                
                ViewContext.Writer.Write("  ");
                
                Html.DevExpress().HyperLink(s => { 
                    s.Name = "linkDel" + c.VisibleIndex; 
                    s.Properties.Text = "删除"; 
                    s.ToolTip = "删除"; 
                    s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_delete.png");
                    s.Properties.ClientSideEvents.Click = "function(){Del('" + DataBinder.Eval(c.DataItem, "FIPGroupID") + "')}";
                    s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
                     
                }).GetHtml();

            });
            column.Settings.AllowDragDrop = DefaultBoolean.False;
            column.Settings.AllowSort = DefaultBoolean.False;
            column.Width = 70;
        });
        
        
        settings.Columns.Add("FIPGroupName", "IP组名称");
        settings.Columns.Add("StrFStartIP", "起始IP");
        settings.Columns.Add("StrFEndIP", "结束IP");
        
        
        settings.SettingsBehavior.AllowSort = false;
        settings.SettingsBehavior.AllowDragDrop = false;
        settings.SettingsBehavior.AllowSelectByRowClick = false;
        settings.SettingsLoadingPanel.Text = "数据读取中...";
        settings.SettingsBehavior.AllowClientEventsOnLoad = false;
        settings.SettingsBehavior.AllowFocusedRow = true;


        settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Pixel(5);

        settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
        settings.SettingsPager.FirstPageButton.Visible = true;
        settings.SettingsPager.LastPageButton.Visible = true;
        settings.SettingsPager.PageSize = ElingOA6_Admin_DSJCJ.Common.GlobalConstant.CONSTRING_PAGESIZE;
        settings.SettingsPager.AlwaysShowPager = true;

        settings.CommandColumn.SetHeaderTemplateContent(c =>
        {
            Html.DevExpress().CheckBox(settingsCheckBox =>
            {
                settingsCheckBox.Name = "cbSelectAll";
                settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectAllRowsOnPage(); else {0}.UnselectAllRowsOnPage(); }}", settings.Name);

                if (c.Grid.VisibleRowCount == 0)
                {
                    settingsCheckBox.Enabled = false;

                }
                else
                {
                    settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
                }


            }).Render();
        });


        settings.PageIndexChanged = (sender, e) =>
        {
            ASPxGridView grid = (ASPxGridView)sender;
            grid.Selection.UnselectAll();
        };
        settings.DataBinding = (sender, e) =>
               {
                   ASPxGridView grid = (ASPxGridView)sender;
                   for (int i = 0; i < grid.AllColumns.Count; i++)
                   {
                       if (grid.AllColumns[i].CellStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                       {
                           grid.AllColumns[i].CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                       }
                       if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                       {
                           grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                       }
                   }
               };
    
    }).Bind(Model).GetHtml()